package com.lxm.shownews.channel.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lxm.shownews.R;
import com.lxm.shownews.bean.ChannelInfo;
import com.lxm.shownews.channel.OnRecyclerViewListener;

import java.util.List;

/**
 * Created by lxm on 2016/3/1.
 */
public class SelectedRecyclerAdapter extends RecyclerView.Adapter<SelectedRecyclerAdapter.SelectedVH> implements View.OnClickListener, View.OnLongClickListener {

    private List<ChannelInfo> channelInfoList;
    private OnRecyclerViewListener mRecyclerViewListener;

    public SelectedRecyclerAdapter(List<ChannelInfo> channelInfoList) {
        this.channelInfoList = channelInfoList;
    }

    public void setmRecyclerViewListener(OnRecyclerViewListener mRecyclerViewListener) {
        this.mRecyclerViewListener = mRecyclerViewListener;
    }

    @Override
    public SelectedVH onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_item_selected, null);
        SelectedVH selectedVH = new SelectedVH(itemView);
        itemView.setOnClickListener(this);
        itemView.setOnLongClickListener(this);
        return selectedVH;
    }

    @Override
    public void onBindViewHolder(SelectedVH holder, int position) {
        holder.badge.setVisibility(View.GONE);
        holder.title.setText(channelInfoList.get(position).getName());
    }

    @Override
    public int getItemCount() {
        return channelInfoList.size();
    }

    @Override
    public void onClick(View v) {
        if (mRecyclerViewListener != null)
            mRecyclerViewListener.onItemClick(v, 0, v.getTag());
    }

    @Override
    public boolean onLongClick(View v) {
        if (mRecyclerViewListener != null)
            return mRecyclerViewListener.onItemLongClick(0, v.getTag());
        return false;
    }


    public static class SelectedVH extends RecyclerView.ViewHolder {
        private TextView title;
        private TextView badge;

        public SelectedVH(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.selected_title);
            badge = (TextView) itemView.findViewById(R.id.selected_badge);
        }
    }

}
